package com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.util.http.HttpClient;
import com.diudiutechnology.www.yadiudiu.util.http.JsonTools;
import com.diudiutechnology.www.yadiudiu.util.utils.MyProgressDialog;
import com.diudiutechnology.www.yadiudiu.util.utils.Sundry;
import com.diudiutechnology.www.yadiudiu.util.utils.ToastUtils;
import com.diudiutechnology.www.yadiudiu.yadiudiu.main.MyActivity.LoginActivity;
import com.diudiutechnology.www.yadiudiu.yadiudiu.model.MessageActivityModel;
import com.diudiutechnology.www.yadiudiu.yadiudiu.model.RegistrationModel;
import com.diudiutechnology.www.yadiudiu.R;

import org.xutils.common.Callback;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/8/24.
 * 消息详情
 */

public class MessageForDetailsActivity extends Activity implements View.OnClickListener {
    @Bind(R.id.retur)
    LinearLayout retur;

    @Bind(R.id.title)//标题
    TextView title;

    @Bind(R.id.content)//内容
            TextView content;

    @Bind(R.id.time)//时间
     TextView time;



    Context context;
    List<MessageActivityModel> message;
    int ints=0;
    private MyProgressDialog mDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message_for_details);
        ButterKnife.bind(this);
        context=this;
        initView();
    }

    private void initView() {
        retur.setOnClickListener(this);
        if (getIntent()!=null){
            ints=getIntent().getIntExtra("ints",0);
            message= (List<MessageActivityModel>) getIntent().getSerializableExtra("data");
        }
        title.setText(message.get(ints).getMsgtitle());
        content.setText(message.get(ints).getMsgcontent());
        if (!Sundry.getStinges(message.get(ints).getAddtime())){
            time.setText(Sundry.getStrsTime(message.get(ints).getAddtime()));
        }
        if (message.get(ints).getMsgstatus().equals("2")){
            initData();
        }

    }

    private void initData(){
        if (Sundry.isOpenNetwork(context)){
          //  mDialog =new MyProgressDialog(context);
            HttpClient.seeMessage(message.get(ints).getId(),new Callback.CommonCallback<String>() {
                @Override
                public void onSuccess(String result) {
//                    if (mDialog != null) {
//                        mDialog.dismiss();
//                    }

                    System.out.println("stringmd5result"+result);
                    List<RegistrationModel> getnote = JsonTools.getunderlying(result);
                    if (getnote!=null||getnote.size()>0){
                        String status = getnote.get(0).getStatus();
                        String getMsg = getnote.get(0).getMsg();
                        if (status.equals("200")){

                    }else if (status.equals("105")){
                            Intent intent = new Intent(context, LoginActivity.class);
                            startActivity(intent);
                            ToastUtils.show(context, getMsg);
                        }else {
                         //   ToastUtils.show(context, getMsg);
                        }
                }
                }

                @Override
                public void onError(Throwable ex, boolean isOnCallback) {
//                    if (mDialog != null) {
//                        mDialog.dismiss();
//                    }
//                    ToastUtils.Toastshow(context, getResources().getString(R.string.server));
                }

                @Override
                public void onCancelled(CancelledException cex) {
//                    if (mDialog != null) {
//                        mDialog.dismiss();
//                    }
//                    ToastUtils.Toastshow(context, getResources().getString(R.string.server));
                }

                @Override
                public void onFinished() {

                }
            });
        }else {
            ToastUtils.Toastshow(context, getResources().getString(R.string.network));
        }
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.retur:
                finish();
                break;
        }
    }
}
